<?php
namespace app\index\job;

use think\queue\Job;

class Test {
    public function fire(Job $job,$data)
    {
        $isJobDone = $this->doJob($data);
        if ($isJobDone) {
            $job->delete();
            print("<info>任务完成并删除"."</info>\n");
        }else{
            if ($job->attempts() > 3) {
                //通过这个方法可以检查这个任务已经重试了几次了
                print("<warn>Hello Job has been retried more than 3 times!"."</warn>\n");

                $job->delete();

                // 也可以重新发布这个任务
                //print("<info>Hello Job will be availabe again after 2s."."</info>\n");
                //$job->release(2); //$delay为延迟时间，表示该任务延迟2秒后再执行
            }
        }
    }

    private function doJob($data)
    {
        print("<info>任务完成啦！</info> \n");

        return true;
    }


}